import request from '@/utils/request'

// 获取所有经销商
export function getAllDealers() {
  return request({
    url: '/api/dealers',
    method: 'get'
  })
}

// 分页获取经销商
export function getDealersByPage(pageNum, pageSize) {
  return request({
    url: '/api/dealers/page',
    method: 'get',
    params: {
      pageNum,
      pageSize
    }
  })
}

// 根据ID获取经销商
export function getDealerById(id) {
  return request({
    url: `/api/dealers/${id}`,
    method: 'get'
  })
}

// 根据用户ID获取经销商
export function getDealerByUserId(userId) {
  return request({
    url: `/api/dealers/user/${userId}`,
    method: 'get'
  })
}

// 搜索经销商
export function searchDealers(params) {
  return request({
    url: '/api/dealers/search',
    method: 'post',
    data: params
  })
}

// 添加经销商
export function addDealer(data) {
  return request({
    url: '/api/dealers',
    method: 'post',
    data
  })
}

// 更新经销商
export function updateDealer(data) {
  return request({
    url: '/api/dealers',
    method: 'put',
    data
  })
}

// 删除经销商
export function deleteDealer(id) {
  return request({
    url: `/api/dealers/${id}`,
    method: 'delete'
  })
}

// 根据用户ID删除经销商
export function deleteDealerByUserId(userId) {
  return request({
    url: `/api/dealers/user/${userId}`,
    method: 'delete'
  })
}

// 查询经销商列表
export function listDealer(query) {
  return request({
    url: '/dealer/list',
    method: 'get',
    params: query
  })
}

// 查询经销商详细
export function getDealer(dealerId) {
  return request({
    url: '/dealer/' + dealerId,
    method: 'get'
  })
}

// 批量删除经销商
export function batchDeleteDealer(dealerIds) {
  return request({
    url: '/dealer/batch/' + dealerIds,
    method: 'delete'
  })
}

// 导出经销商
export function exportDealer(query) {
  return request({
    url: '/dealer/export',
    method: 'get',
    params: query,
    responseType: 'blob'
  })
}

// 导入经销商
export function importDealer(data) {
  return request({
    url: '/dealer/import',
    method: 'post',
    data: data
  })
}

// 上传Logo
export function uploadLogo(data) {
  return request({
    url: '/dealer/upload',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取经销商的车辆列表
export function getDealerCars(dealerId) {
  return request({
    url: '/getDealerCars/' + dealerId,
    method: 'get'
  })
}

// 获取经销商的交易记录
export function getDealerTransactions(dealerId) {
  return request({
    url: '/getDealerTransactions/' + dealerId,
    method: 'get'
  })
} 